﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using NUnit.Framework;

namespace COFE.Core.Actions
{
    //[Work("script", false)]
    public class ScriptableWork : ActionWork
    {
        #region Constructor

        public ScriptableWork(Guid id, IEntryList input, Stream script, IScriptParser parser)
            : base(id, input)
        {
            Assert.IsNotNull(parser);
            _parser = parser;
            this.Actions = parser.ParseScript(script);
        }

        public ScriptableWork(Guid id, IEntryList input, string script, IScriptParser parser)
            : base(id, input)
        {
            Assert.IsNotNull(parser);
            _parser = parser;
            this.Actions = parser.ParseScript(script);
        }

        #endregion

        #region Methods

        //protected override void GetObjectData(Dictionary<string, string> paramDic)
        //{
        //    base.GetObjectData(paramDic);

        //    using (var sr = new StreamReader(Script))
        //        paramDic.Add("script", sr.ReadToEnd());
        //}

        //protected override void SetObjectData(Dictionary<string, string> paramDic)
        //{
        //    base.SetObjectData(paramDic);

        //    var ms = new MemoryStream();
        //    var sw = new StreamWriter(ms);
        //    sw.Write(paramDic["script"]);
        //    ms.Seek(0, SeekOrigin.Begin);

        //    this.Actions = Parser.ParseScript(ms);
        //}
        #endregion

        #region Data

        private IScriptParser _parser;

        #endregion

        #region Public Properties

        public IScriptParser Parser { get { return _parser; } }
        public Stream Script { get { return _parser.GenerateScript(Actions); } }

        #endregion

    }
}
